package com.school.admin.common.config;

import cn.hutool.core.io.FileUtil;
import com.school.admin.common.utils.RsaUtils;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.nio.charset.StandardCharsets;

/**
 * @author ：sunpx
 * @date ：Created in 2021/7/10 11:24
 * @description：
 * @modified By：
 * @version: $
 */
@Data
@Configuration
public class InjectionParameters {

    @Value("${top.sunpxit.ras.private-key}")
    private String privateKey;

    @Value("${top.sunpxit.ras.public-key}")
    private String publicKey;


    /**
     * 加载秘钥
     *
     * @author : sunpx
     * @date : 2022-04-20 16:05:47
     */
    @PostConstruct
    public void init() {
        // FileUtil
        String prKey = FileUtil.readString(privateKey, StandardCharsets.UTF_8);
        String puKey = FileUtil.readString(publicKey, StandardCharsets.UTF_8);
        privateKey = prKey;
        publicKey = puKey;
        RsaUtils.setConfigInfo(this);
    }

}
